package com.lbt.mybatis.plus.extend.demo.mybatis;

import cn.hutool.core.date.LocalDateTimeUtil;
import com.lbt.mybatis.plus.extend.field.FieldValueFormatter;

import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;

/**
 * @author zhangjinyu
 * @since 2023-05-18
 */
public class LocalDateTimeBetweenSingleFieldValueFormatter implements FieldValueFormatter<LocalDateTime[]> {
    @Override
    public boolean support(Object obj) {
        return obj instanceof String;
    }

    @Override
    public LocalDateTime[] format(Object obj) {
        LocalDateTime start = LocalDateTimeUtil.parse((CharSequence) obj, "yyyy-MM-dd hh:mm:ss");
        LocalDateTime end = start.plus(1, ChronoUnit.DAYS);
        return new LocalDateTime[]{start, end};
    }
}
